package com.ccq.service;

import com.alibaba.fastjson.JSON;
import com.ccq.mapper.RentingMapper;
import com.ccq.model.Renting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LastRentingService {

    @Autowired
    RentingMapper rentingMapper;

    public String rentlist(Integer page){
        page=(page-1)*5;
        List<Renting> ls=rentingMapper.selectPage(page);
        String aListJson = JSON.toJSONString(ls);
        System.out.println(aListJson);
        return aListJson;
    }

    public String add(Renting renting){
        int add=rentingMapper.insertSelective(renting);
        List<Renting> ls=rentingMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String eidts(int id){
        Renting se=rentingMapper.selectByPrimaryKey(id);
        String aListJson = JSON.toJSONString(se);
        return aListJson;
    }

    public String edit(Renting renting){
        int  se=rentingMapper.updateByPrimaryKey(renting);
        List<Renting> ls=rentingMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        return aListJson;
    }

    public String del(int id){
        int del=rentingMapper.deleteByPrimaryKey(id);
        List<Renting> ls=rentingMapper.selectPage(0);
        String aListJson = JSON.toJSONString(ls);
        System.out.println("删除成功！");
        return aListJson;
    }
}
